package com.xc.xcoj.judge.strategy;

import com.xc.xcoj.model.enums.QuestionSubmitLanguageEnum;
import org.springframework.beans.factory.InitializingBean;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 工厂类
 *
 * @author zqx
 * @since 2024/10/20
 */
public class JudgeStrategyFactory implements InitializingBean {

    @Resource
    private List<JudgeStrategy> judgeStrategieList;

    private static Map<QuestionSubmitLanguageEnum, JudgeStrategy> judgeStrategyMap = new HashMap<>();

    public static JudgeStrategy getIntance(String languageType) {
        QuestionSubmitLanguageEnum languageEnum = QuestionSubmitLanguageEnum.getEnumByText(languageType);
        return judgeStrategyMap.get(languageEnum);
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        for (JudgeStrategy judgeStrategy : judgeStrategieList) {
            judgeStrategyMap.put(judgeStrategy.getLanguage(),judgeStrategy);
        }
    }
}
